﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific.AppCompat;

namespace CnBlogsClient.Views
{
    public class XamNavigationPage : Xamarin.Forms.NavigationPage
    {
        private DateTime firstBackPressedTime = DateTime.MinValue;
        public XamNavigationPage(Page root) : base(root)
        {
            Init();
            Title = root.Title;
        }

        public XamNavigationPage()
        {
            Init();
        }

        void Init()
        {
        }

        protected override bool OnBackButtonPressed()
        {
            if (Device.RuntimePlatform == Device.Android && this.RootPage == this.CurrentPage)
            {
                if (firstBackPressedTime == DateTime.MinValue || firstBackPressedTime.AddSeconds(3) < DateTime.Now)
                {
                    firstBackPressedTime = DateTime.Now;
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return base.OnBackButtonPressed();
        }
    }
}